/**
 * 
 */
package com.greatwideweb.runhelper.tasks;

import com.greatwideweb.runhelper.RunItem;
import com.greatwideweb.runhelper.db.DatabaseAdapter;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

/**
 * @author dave
 *
 */
public class SaveRunTask extends AsyncTask<RunItem, Void, String> {

  Context context;
  ISaveRunObserver observer;
  public SaveRunTask(Context c, ISaveRunObserver o) {
    context = c;
    observer = o;
  }
  @Override
  protected void onPostExecute(String result) {
    // TODO Auto-generated method stub
    Log.d("onPostExecute", result);
    super.onPostExecute(result);
    observer.onSaveResult(result);
  }

  @Override
  protected String doInBackground(RunItem... arg0) {
    // TODO Auto-generated method stub
    Log.d("doInBackground", arg0[0].toString());
    DatabaseAdapter dbAdapter = new DatabaseAdapter(context).open();
    dbAdapter.saveRun(arg0[0]);
    dbAdapter.close();
    return "run details been saved";
  }

}
